package code.D1216;

/**
 * author : yeswater
 * date : 2023/12/16
 * 
 * 打家劫舍
 * 
 */

public class T198 {
    public int rob(int[] nums) {
        int[] dp = new int[nums.length + 1];
        dp[0] = 0;
        dp[1] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i+1] = Math.max(dp[i], dp[i-1] + nums[i]);
        }
        int max = 0;
        for (int num : dp) {
            max = Math.max(max, num);
        }
        return max;
    }
    
    public int rob1(int[] nums) {
        int pre = 0, cur = 0, tmp;
        for (int num : nums) {
            tmp = cur;
            cur = Math.max(pre + num, cur);
            pre = tmp;
        }
        return cur;
    }
}
